import React, {Component} from 'react';
import {connect} from 'react-redux'
import {Redirect, Route, Switch} from 'react-router-dom'
import {createDeleteUserInfoAction} from '../../redux/actions/login_action.js'
import {Layout} from 'antd';
import Header from './header/Header.js'
import LeftNav from "./left_nav/left_nav.jsx"

import Home from '../home/Home.jsx'
import Category from "../category/Category.jsx";
import Product from "../product/Product.jsx";
import User from "../user/User.jsx";
import Role from "../role/Role.jsx";
import Bar from "../bar/Bar.jsx";
import Line from "../line/Line.jsx"
import Pie from "../pie/Pie.jsx";
import AddUpdate from "../product/addUpdate/AddUpdate.jsx"
import Detail from "../product/detail/Detail.jsx"

import "./css/admin.less"

const { Footer, Content } = Layout;

// @connect(
//   state => ({userInfo: state.userInfo}),
//   {
//     deleteUserInfo: createDeleteUserInfoAction
//   }
// )
class AdminContainer extends Component {
  render() {
    let {isLogin} = this.props.userInfo
    // 已经登录
    if (isLogin) {
      return <Layout className="layout">
        {/* 侧边栏 */}
        <LeftNav/>
        
        {/* 右侧内容*/}
        <Layout>
          {/* 头部 */}
          <Header></Header>
          {/* 中间内容 */}
          <Content className="content">
            <Switch>
              <Route path="/admin/home" component={Home}/>
              <Route path="/admin/prod_about/category" component={Category}/>
              <Route path="/admin/prod_about/product/addUpdate" component={AddUpdate}/>
              <Route path="/admin/prod_about/product/detail/:id" component={Detail}/>
              <Route path="/admin/prod_about/product" component={Product}/>
              <Route path="/admin/user" component={User}/>
              <Route path="/admin/role" component={Role}/>
              <Route path="/admin/charts/bar" component={Bar}/>
              <Route path="/admin/charts/line" component={Line}/>
              <Route path="/admin/charts/pie" component={Pie}/>
              <Redirect to="/admin/home" component={Home}/>
            </Switch>
            
          </Content>
          {/* 底部 */}
          <Footer className="footer">
            推荐使用谷歌浏览器，可以获得最佳页面操作体验
          </Footer>
        </Layout>
      </Layout>
    } else {
      // 没有登录，跳转到login页面
      return <Redirect to="/login"/>
    }
  }
}

export default connect(
  state => ({userInfo: state.userInfo, title: state.leftMenuTitle}),
  {
    deleteUserInfo: createDeleteUserInfoAction,
  }
)(AdminContainer)

// export default AdminContainer
